{% extends 'front/base.html' %}
{% from 'front/_macros.html' import pagination_widget as render_page %}
{% block content %}
    <div class="r_box">
    {% for club in club_list %}
    <li>
{#        <i><img src="{{ url_for('static', filename='simple/images/3.jpg') }}"></i>#}
        <div class="club-box">
            <div>
                <h3>{{club.name |safe}}</h3>
                <div style="margin-top: 1rem;">
                    {{ club.introduction |safe}}
                </div>
            </div>
{#            <button class="fa fa-car" style="font-size:3rem;color:green;"></button>#}
            <div>
                <a href="{{ url_for('main.access_club', club_id=club.id) }}" class="access-btn"  target="_blank">
                <i class="fa fa-rocket" aria-hidden="true"></i>访问
                </a>
            </div>

        </div>
    </li>
    {% endfor %}
    <li>
        {{ render_page(pagination, endpoint)}}
    </li>
{#    <div class="entry-box submit-article" id="access-box" style="display: none">#}
{#        <form class="submit-article" method="post" action="" id="form-old">#}
{#            {{ form.csrf_token }}#}
{#            <input type="text" value="to-be-replace" name="club_id" style="display: none" id="club_id" />#}
{#            <div class="form-group">#}
{#                <label for="password">访问密码</label>#}
{#                <input type="text" name="password" id="password" class='submit-access-password form-control' required=''>#}
{#            </div>#}
{#            <div class="submit-access-button">#}
{#                <button type="button" id="mod-go-access" class="btn btn-success">提交</button>#}
{#            </div>#}
{#        </form>#}
{#    </div>#}
  </div>
{% endblock %}
{% block scripts %}
{#    {{ super() }}#}
    <script>
        function showBox(club_id){
            console.log(club_id)
            let request_html = jQuery("#access-box").html()
            let re = new RegExp("to-be-replace","g"); //定义正则表达式
            let ret = new RegExp("form-old","g"); //定义正则表达式
            let rete = new RegExp("mod-go-access","g"); //定义正则表达式
            //第一个参数是要替换掉的内容，第二个参数"g"表示替换全部（global）。
            let NewStr = request_html.replace(re, club_id.toString()); //第一个参数是正则表达式。
            let newString = NewStr.replace(ret, "form"); //第一个参数是正则表达式。
            let new_string = newString.replace(rete, "go-access"); //第一个参数是正则表达式。
            console.log(new_string)
            layer.open({
              type: 1, title: '输入访问密码',
              skin: 'layui-layer-demo', //样式类名
              closeBtn: 1, //不显示关闭按钮
              anim: 2,
              shadeClose: true, //开启遮罩关闭
              content: new_string
            });
        }
        jQuery("#go-access").on("click", function (){
            console.log($('#form').serialize())
            $.ajax({
            type: "post",   //请求类型
            dataType: "json",   //请求数据返回类型
            url: "/admin/json_data/sent_data",    //请求地址
            data: $('#form').serialize(),       //表单序列化
            success: function (result) {        //成功
                console.log(result);
                if (result.code === 200) {
                    console.log(result);
                    console.log("成功");
                    {#$("#club_id").text(result.data.name);#}
                    {#$("#password").text(result.data.phone);#}
                } else {
                    console.log(result);
                    console.log("失败");
                }
            },
            error: function (result) {      //失败
                console.log(result);
                console.log("异常");
            }
        });
        return false;
        })
    </script>
{% endblock %}